home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / awt / filedial.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  3.9 KB  |  154 lines

  1. /*
  2.  * @(#)FileDialog.java    1.8 95/09/08 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. import java.awt.peer.FileDialogPeer;
  22. import java.io.FilenameFilter;
  23.  
  24. /**
  25.  * The File Dialog class displays a file selection dialog. It is a
  26.  * modal dialog and will block the calling thread when the show method
  27.  * is called to display it until the user has chosen a file.
  28.  *
  29.  * @see Dialog#show
  30.  *
  31.  * @version     1.8, 09/08/95
  32.  * @author     Sami Shaio
  33.  * @author     Arthur van Hoff
  34.  */
  35. public class FileDialog extends Dialog {
  36.     
  37.     /**
  38.      * The file load variable.
  39.      */
  40.     public static final int LOAD = 0;
  41.  
  42.     /**
  43.      * The file save variable.
  44.      */
  45.     public static final int SAVE = 1;
  46.  
  47.     int mode;
  48.     String dir;
  49.     String file;
  50.     FilenameFilter filter;
  51.  
  52.     /**
  53.      * Creates a file dialog for loading a file.
  54.      * @param parent the owner of the dialog
  55.      * @param title the title of the Dialog
  56.      */
  57.     public FileDialog(Frame parent, String title) {
  58.     this(parent, title, LOAD);
  59.     }
  60.  
  61.     /**
  62.      * Creates a file dialog with the specified title and mode.
  63.      * @param parent the owner of the dialog
  64.      * @param title the title of the Dialog
  65.      * @param mode the mode of the Dialog
  66.      */
  67.     public FileDialog(Frame parent, String title, int mode) {
  68.     super(parent, title, true);
  69.     this.mode = mode;
  70.     }
  71.  
  72.     /**
  73.      * Creates the frame's peer.  The peer allows us to change the look
  74.      * of the file dialog without changing its functionality.
  75.      */
  76.     public synchronized void addNotify() {
  77.     peer = getToolkit().createFileDialog(this);
  78.     super.addNotify();
  79.     }
  80.  
  81.     /**
  82.      * Gets the mode of the file dialog.
  83.      */
  84.     public int getMode() {
  85.     return mode;
  86.     }
  87.  
  88.     /**
  89.      * Gets the directory of the Dialog.
  90.      */
  91.     public String getDirectory() {
  92.     return dir;
  93.     }
  94.  
  95.     /**
  96.      * Set the directory of the Dialog to the specified directory.
  97.      * @param dir the specific directory
  98.      */
  99.     public void setDirectory(String dir) {
  100.     this.dir = dir;
  101.     FileDialogPeer peer = (FileDialogPeer)this.peer;
  102.     if (peer != null) {
  103.         peer.setDirectory(dir);
  104.     }
  105.     }
  106.  
  107.     /**
  108.      * Gets the file of the Dialog.
  109.      */
  110.     public String getFile() {
  111.     return file;
  112.     }
  113.  
  114.     /**
  115.      * Sets the file for this dialog to the specified file. This will 
  116.      * become the default file if set before the dialog is shown.
  117.      * @param file the file being set
  118.      */
  119.     public void setFile(String file) {
  120.     this.file = file;
  121.     }
  122.     
  123.     /**
  124.      * Gets the filter.
  125.      */
  126.     public FilenameFilter getFilenameFilter() {
  127.     return filter;
  128.     }
  129.  
  130.     /**
  131.      * Sets the filter for this dialog to the specified filter.
  132.      * @param filter the specified filter
  133.      */
  134.     public void setFilenameFilter(FilenameFilter filter) {
  135.     this.filter = filter;
  136.     FileDialogPeer peer = (FileDialogPeer)this.peer;
  137.     if (peer != null) {
  138.         peer.setFilenameFilter(filter);
  139.     }
  140.     }
  141.  
  142.     /**
  143.      * Returns the parameter String of this file dialog.
  144.      * Parameter String.
  145.      */
  146.     protected String paramString() {
  147.     String str = super.paramString();
  148.     if (dir != null) {
  149.         str += ",dir= " + dir;
  150.     }
  151.     return str + ((mode == LOAD) ? ",load" : ",save");
  152.     }
  153. }
  154.